from PyQt6.QtWidgets import QTreeWidget, QTreeWidgetItem, QPushButton


class TreeWindow(QTreeWidget):

    def __init__(self):
        super().__init__()

        self.setColumnCount(2)
        self.setHeaderLabels(['Key', 'Value'])

        # 创建根节点
        root = QTreeWidgetItem(self)
        root.setText(0, 'Root')
        root.setText(1, 'root_value')

        # 添加子节点
        child1 = QTreeWidgetItem(root)
        child1.setText(0, 'Child 1')
        child1.setText(1, 'child1_value')

        child2 = QTreeWidgetItem(root)
        child2.setText(0, 'Child 2')
        child2.setText(1, 'child2_value')

        # 添加子节点的子节点
        grandchild = QTreeWidgetItem(child1)
        grandchild.setText(0, 'Grandchild')
        grandchild.setText(1, 'grandchild_value')

    # # 设置数据
    # def setData(self, jsonStr: SupportsRead[typing.Union[str, bytes]]):
    #     data = json.load(jsonStr)
    #
    # # 设置数节点头
    # def setTreeHead(self, labels: typing.Iterable[typing.Optional[str]]):
    #     self.setColumnCount(2)
    #     self.setHeaderLabels(labels)
